package wt.hpad.utils;

import android.os.Handler;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created by wt on 2017-7-28.
 */

public class ThreadUtil {
    private static Handler hanlder = new Handler();
    private static final int count = 10;


    private static ExecutorService mThreadExecutor;

    public static void buildPool() {
        if (mThreadExecutor != null) {
            mThreadExecutor.shutdownNow();
            mThreadExecutor = null;
        }
        mThreadExecutor = Executors.newFixedThreadPool(count);
    }

    public static void excute(Runnable task) {
        mThreadExecutor.execute(task);
    }

    public static void shutDown() {
        mThreadExecutor.shutdown();
    }

    public static boolean isTerminated() {
        return mThreadExecutor.isTerminated();
    }

    public static boolean isShutDown() {
        return mThreadExecutor.isShutdown();
    }

    public static void runOnUI(Runnable runnable) {
        hanlder.post(runnable);
    }
}
